/*
 *  Copyright (C) 2010 glauco
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.swing.commons;

import javax.swing.JLabel;
import org.balisunrise.common.EntityFieldType;
import org.balisunrise.common.abstracts.AbstractFieldComponent;

/**
 *
 * @author Glauco
 */
public class FieldLabel extends AbstractFieldComponent
        implements org.balisunrise.common.FieldLabel<JLabel>{

    public static final String PROP_VISUAL_REPRESENTATION =
            "visualRepresentation";

    
    private JLabel visualRepresentation;
    

    public FieldLabel(JLabel visualRepresentation) {
        this.visualRepresentation = visualRepresentation;
        setName(visualRepresentation.getName());
    }

    /**
     * Atribui o texto a ser exibido pelo rótulo.
     */
    @Override
    public void setText(String text) {
        visualRepresentation.setText(text);
    }

    /**
     * Retorna o texto exibido pelo rótulo.
     */
    @Override
    public String getText() {
        return visualRepresentation.getText();
    }

    /**
     * FieldLabel não receberá Focus.
     * @return sempre falso.
     */
    @Override
    public boolean requestFocus() {
        return false;
    }

    /**
     * FieldLabel não pode ser abilitado ou desabilitado.
     * @param value
     * @return sempre falso.
     */
    @Override
    public boolean setEnabled(boolean value) {
        return false;
    }

    /**
     * Retorna a Representação Visual.
     * @return um componente JLabel.
     */
    @Override
    public JLabel getVisualRepresentation() {
        return visualRepresentation;
    }

    /**
     * Atribui a Representação Visual.
     */
    public void setVisualRepresentation(JLabel visualRepresentation) {
        JLabel oldVisualRepresentation = this.visualRepresentation;
        this.visualRepresentation = visualRepresentation;
        changeSupport.firePropertyChange(PROP_VISUAL_REPRESENTATION,
                oldVisualRepresentation, visualRepresentation);
    }

    /**
     * Tipo de Campo de Entidade.
     * @return EntityFieldType.LABEL
     */
    @Override
    public EntityFieldType getEntityFieldType() {
        return EntityFieldType.LABEL;
    }

}
